<script type="text/javascript">
<!--
$(document).ready(function(){
							$('.tuan').hide();
							});

//-->
</script>
 <h3 style="margin-top: 0px;">Xin vui lòng kiểm tra thời gian bạn muốn lập kế hoạch đã tồn tại hay chưa</h3>
	<table cellpadding="0" cellspacing="0" id="tables">

	<tr>
			<th><?php echo 'STT';?></th>
			<th><?php echo 'Thời Gian';?></th>
			<th class="actions"><?php __('Lựa chọn');?></th>
			<th class="status"><?php __('Trạng Thái');?></th>
	</tr>
	<?php
	$i = 0;$sttthang=0;$stttuan=0;
	foreach ($kehoachthangs as $kehoachthang):
		$thanght = date('m',strtotime($kehoachthang['Thoigian']['ngaykt']));
		$class = null;
		$id=null;
		$align =null;
		$khcngay =date('d-m-Y',strtotime($kehoachthang['Thoigian']['ngaykt']))-date('d-m-Y',strtotime($kehoachthang['Thoigian']['ngaybd']));
	/*
		if ($sttthang>0)
			echo $form->input('', array('type'=>'hidden','value'=>$stttuan,'id'=>'sotuan'.$sttthang));
	*/
		$sttthang++;
		
		
		$id = ' id ='.$sttthang;
	?>
	<tr<?php echo $class.$id;?>>
		<td ><?php
		 		if ($khcngay>=8)
		 		{
					echo $sttthang;
		 		} 
		 ?>&nbsp;</td>
		<td <?php echo $align?>>
			<?php
			echo $html->image('/img/plus.png', array('class'=>'plus','id'=>$sttthang));
			 echo '<strong>'.$kehoachthang['Thoigian']['thoigian'].'</strong>'; ?>
		</td>
       
        
		<td class="actions">
			<?php if($madv[0] [0] ['ma'] == 'TT') { // neu la trung tam
                     {
                                echo $this->Html->link(__('Chỉ tiêu tháng', true), array('controller'=>'chitieunvs','action' => 'hienchitieuthang', $kehoachthang['Kehoach']['id']));
                      }
                      $str = "Cho Nhân Viên";
                    }
                    Elseif($madv[0] [0] ['ma'] == 'CN')
                    { // neu la chi nhanh
	                    echo $this->Html->link(__('Chỉ tiêu', true), array('controller'=>'chitieudvs','action' => 'hienchitieu', $kehoachthang['Kehoach']['id']));
				        $str = "Cho Trung Tâm";
                    }
                    else
                    {// neu la trung tam
                    	echo $this->Html->link(__('Chỉ tiêu', true), array('controller'=>'chitieudvs','action' => 'hienchitieu', $kehoachthang['Kehoach']['id']));
				        $str = "Cho Chi Nhánh";
                    }
                    ?>
		</td>
		<td class="status" align='center'>
			<?php
                     if ($kehoachthang['Kehoach']['dagiao']==1)
                      	{
                      		echo $form->label('','Đã Giao '.$str);
                      	}
                      	else
                      	{
                      		echo $form->label('','Chưa Giao '.$str);                      		
                      	}
                    ?>
		</td>
		
		
	</tr>
	<?php
			$stttuan=0; 
	foreach ($kehoachtuans as $kehoachtuan):
			$thangoftuan = date('m',strtotime($kehoachtuan['Thoigian']['ngaykt']));
		if($thanght==$thangoftuan)
		{
			$class = null;
			$id=null;
			$align =null;
			$stttuan++;
			$class = ' class = tuan ';
			$id = ' id =tuan'.$sttthang.$stttuan;
			$align = ' align=right';
	?>
	<tr<?php echo $class.$id;?>>
		<td ><?php
		 ?>&nbsp;</td>
		<td <?php echo $align?>>
			<?php echo $kehoachtuan['Thoigian']['thoigian']; ?>
		</td>
       
        
		<td class="actions">
			<?php if($madv[0] [0] ['ma'] == 'TT') { // neu la trung tam
                     {
                                echo $this->Html->link(__('Chỉ tiêu Tuần', true), array('controller'=>'chitieunvs','action' => 'hienchitieu', $kehoachtuan['Kehoach']['id']));
                      }
                      $str = "Cho Nhân Viên";
                    }
                    ?>
		</td>
		<td class="status">
			<?php
                     if ($kehoachtuan['Kehoach']['dagiao']==1)
                      	{
                      		echo $form->label('','Đã Giao '.$str);
                      	}
                      	else
                      	{
                      		echo $form->label('','Chưa Giao '.$str);                      		
                      	}
                    ?>
		</td>
		
		
	</tr>
	<?php }
		endforeach; 
		if ($sttthang>0)
			echo $form->input('', array('type'=>'hidden','value'=>$stttuan,'id'=>'sotuan'.$sttthang));
	endforeach; ?>
	</table>